# Install/load packages
source("code/install.R") # When prompted, type 1 or your preference

# Print message
print("Starting replication...")

########################################
### START PORTING OUTPUT TO LOG FILE ###
########################################

sink("replication_log.txt")

##################
### MAIN PAPER ###
##################

# Generate and analyze `typical` perceived distributions
# Note: Generates Figure 2 and Supplementary Tables 2 and 3
source("code/in_main_paper/descriptives_and_placebos.R")

# Estimate effect of numeracy on perceived-distribution moments
# Note: Generates Supplementary Tables 4 and 5
source("code/in_main_paper/numeracy.R")

# Estimate effect of incentives on perceived-distribution moments
# Note: Generates Supplementary Tables 6, 7, 11, and 12
source("code/in_main_paper/incentives.R")

# Check criterion validity of perceived distribution moments
# Note: Generates Figure 3 and Supplementary Tables 8 and 9
source("code/in_main_paper/criterion_validity.R")

# Plot distribution of perceived-distribution moments
# Note: Generates Figure 4
source("code/in_main_paper/moment_distributions.R")

# Estimate effect of question type on estimates of perceived polarization
# Note: Generates Figure 5 and Supplementary Table 10
source("code/in_main_paper/question_differences.r")

################
### APPENDIX ###
################

# Generate Supplementary Table 1
source("code/in_appendix_only/sample_demos.R")

# Calculate survey-index alphas
source("code/in_appendix_only/index_alphas.R")

# Generate Supplementary Table 13
source("code/in_appendix_only/robust_q_wording.R")

#######################################
### STOP PORTING OUTPUT TO LOG FILE ###
#######################################

sink()

# Print message
print("Replication done! See output in replication_log.txt.")
